<?php 
include_once 'site_config.php';
include_once "ra_global.php";
if($_GET['uid']){
	$user=$db->ig2_want('mae_user','id='.$_GET['uid'].' and is_delete=0');
	if(!$user){
		echo '<script>location.href="user.php";</script>';
	}
}else{
	if(!$_GET['code']){
		echo "<script language=javascript>location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'wishlist.php')."&response_type=code&scope=snsapi_base&state=1#wechat_redirect';</script>";
	}

	//获取code
	$getcode=getToken("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$_GET['code']."&grant_type=authorization_code");
	$user_obj=json_decode($getcode);

	if($user_obj->openid){
		$user=$db->ig2_want('mae_user','openid="'.trim($user_obj->openid).'" and is_delete=0');
		if(!$user){
			echo '<script>location.href="user.php";</script>';
		}
	}else{
		echo "<script language=javascript>location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'wishlist.php')."&response_type=code&scope=snsapi_base&state=1#wechat_redirect';</script>";
	}
}

function getToken($url){
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
	$row=curl_exec($ch); 
	return $row;
}

$sday=date('Y-m-',time()).'1';
$eday=date('Y-m-d',strtotime("$sday +1 month"));
$sday=strtotime($sday);
$eday=strtotime($eday);
$nofill=$db->ig2_want("mae_wish_list","uid=".$user['id']." and create_time >= $sday and create_time < $eday and status=0");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href="images/m.css" rel="stylesheet" type="text/css" />
<script src="inc/jquery.min.js" type="text/javascript"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript"></script>
<title>喜力超凡大师</title>
</head>
<?php if($user){?>
<body>
<script language="javascript">
function onBridgeReady(){
	WeixinJSBridge.call('hideOptionMenu');
}

if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	}else if (document.attachEvent){
	document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
}else{
	onBridgeReady();
}
</script>
<div class="container" style="display:none">
	<img id="wishbg" src="images/wishbg.jpg">
	<!--  列表  -->
	<div id="wishlist" class="bt">
		<?php foreach($db->ig2_select('mae_wish_list','uid='.$user['id'].' and status=2 and is_see=0 order by create_time desc') as $list){?>
		<li>
			<img class="wishlibg" src="images/wishlibg.jpg">
			<img class="wishlist_1 bt" src="<?php echo trim($list['image'])?(file_exists('./logo/'.trim($list['image']))?('logo/'.trim($list['image'])):'images/wishlist_1.jpg'):'images/wishlist_1.jpg'?>">
			<img class="wishlist_2 bt" id="wishlist_2_<?php echo $list['id']?>" src="images/wishlist_2.jpg" onClick="seeWishInfo(<?php echo $list['id']?>)">
            <div id="wishlist_5_div_<?php echo $list['id']?>"><img class="wishlist_5 bt" id="wishlist_5_<?php echo $list['id']?>" src="images/wishlist_5.jpg" onClick="seeWishInfo(<?php echo $list['id']?>)"></div>
            <script>
				document.getElementById("wishlist_5_<?php echo $list['id']?>").addEventListener("touchstart", touchStartwishlist_5_<?php echo $list['id']?>, false);
				document.getElementById("wishlist_5_<?php echo $list['id']?>").addEventListener("touchend", touchEndwishlist_5_<?php echo $list['id']?>, false);
				function touchStartwishlist_5_<?php echo $list['id']?>(event){
					startX = event.touches[0].clientX;
					document.getElementById('wishlist_5_<?php echo $list['id']?>').src='images/wishlist_5_h.jpg';	
				}
				function touchEndwishlist_5_<?php echo $list['id']?>(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('wishlist_5_<?php echo $list['id']?>').src='images/wishlist_5.jpg';
				}	
				document.getElementById("wishlist_2_<?php echo $list['id']?>").addEventListener("touchstart", touchStartwishlist_2_<?php echo $list['id']?>, false);
				document.getElementById("wishlist_2_<?php echo $list['id']?>").addEventListener("touchend", touchEndwishlist_2_<?php echo $list['id']?>, false);
				function touchStartwishlist_2_<?php echo $list['id']?>(event){
					startX = event.touches[0].clientX;
					document.getElementById('wishlist_2_<?php echo $list['id']?>').src='images/wishlist_2_h.jpg';	
				}
				function touchEndwishlist_2_<?php echo $list['id']?>(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('wishlist_2_<?php echo $list['id']?>').src='images/wishlist_2.jpg';
				}	
			</script>
			<label class="wishlist_3 bt"><?php echo date('Y-m-d',$list['create_time'])?></label>
			<label id="wishlist_4_<?php echo $list['id']?>" class="wishlist_4 bt">【<?php switch($list['status']){
				case 1 : echo '未实现'; break;
				case 2 : echo '已实现'; break;
				case 3 : echo '已评价'; break;
				default : echo '-'; break;
			}?>】</label>	
		</li>
		<?php }?>
		<?php foreach($db->ig2_select('mae_wish_list','uid='.$user['id'].' and ((status>0 && status!=2) or (status=2 && is_see=1)) order by create_time desc') as $list){?>
		<li>
			<img class="wishlibg" src="images/wishlibg.jpg">
			<img class="wishlist_1 bt" src="<?php echo trim($list['image'])?(file_exists('./logo/'.trim($list['image']))?('logo/'.trim($list['image'])):'images/wishlist_1.jpg'):'images/wishlist_1.jpg'?>">
			<img class="wishlist_2 bt" id="wishlist_2_<?php echo $list['id']?>" src="images/wishlist_2.jpg" onClick="seeWishInfo(<?php echo $list['id']?>)">
            <?php if($list['status'] == 2){?>
			<img class="wishlist_5 bt" id="wishlist_5_<?php echo $list['id']?>" src="images/wishlist_5.jpg" onClick="seeWishInfo(<?php echo $list['id']?>)">
            <script>
				document.getElementById("wishlist_5_<?php echo $list['id']?>").addEventListener("touchstart", touchStartwishlist_5_<?php echo $list['id']?>, false);
				document.getElementById("wishlist_5_<?php echo $list['id']?>").addEventListener("touchend", touchEndwishlist_5_<?php echo $list['id']?>, false);
				function touchStartwishlist_5_<?php echo $list['id']?>(event){
					startX = event.touches[0].clientX;
					document.getElementById('wishlist_5_<?php echo $list['id']?>').src='images/wishlist_5_h.jpg';	
				}
				function touchEndwishlist_5_<?php echo $list['id']?>(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('wishlist_5_<?php echo $list['id']?>').src='images/wishlist_5.jpg';
				}	
			</script>
			<?php }?>
            <script>
				document.getElementById("wishlist_2_<?php echo $list['id']?>").addEventListener("touchstart", touchStartwishlist_2_<?php echo $list['id']?>, false);
				document.getElementById("wishlist_2_<?php echo $list['id']?>").addEventListener("touchend", touchEndwishlist_2_<?php echo $list['id']?>, false);
				function touchStartwishlist_2_<?php echo $list['id']?>(event){
					startX = event.touches[0].clientX;
					document.getElementById('wishlist_2_<?php echo $list['id']?>').src='images/wishlist_2_h.jpg';	
				}
				function touchEndwishlist_2_<?php echo $list['id']?>(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('wishlist_2_<?php echo $list['id']?>').src='images/wishlist_2.jpg';
				}	
			</script>
			<label class="wishlist_3 bt"><?php echo date('Y-m-d',$list['create_time'])?></label>
			<label id="wishlist_4_<?php echo $list['id']?>" class="wishlist_4 bt">【<?php switch($list['status']){
				case 1 : echo '未实现'; break;
				case 2 : echo '已实现'; break;
				case 3 : echo '已评价'; break;
				default : echo '-'; break;
			}?>】</label>	
		</li>
		<?php }?>
		<?php if(!$nofill){?>
		<img id="wishbottom" src="images/wishbottom.jpg">
		<?php }else{?>
		<div id="wishfooter" class="bt">
			<img id="wishfooterbg" src="images/wishfooterbg.jpg">	
			<img id="wishfooterbt" class="bt" src="images/wishfooterbt.jpg" onClick="location.href='wish.php?wishid=<?php echo $nofill['id']?>'">
            <script>
				document.getElementById("wishfooterbt").addEventListener("touchstart", touchStartwishfooterbt, false);
				document.getElementById("wishfooterbt").addEventListener("touchend", touchEndwishfooterbt, false);
				function touchStartwishfooterbt(event){
					startX = event.touches[0].clientX;
					document.getElementById('wishfooterbt').src='images/wishfooterbt_h.jpg';	
				}
				function touchEndwishfooterbt(event){
					endX = event.changedTouches[0].clientX;
					document.getElementById('wishfooterbt').src='images/wishfooterbt.jpg';
				}	
			</script>
		</div>	
		<?php }?>	
	</div>
	<div id="seeWishInfoDiv"></div>
</div> 
<script type="text/javascript">
var x,y,p;
var starcount=0;
$(document).ready(function() {
	x=parseInt(window.innerWidth);
	y=parseInt(window.innerHeight);
	p=720/x;
	getWidth(); 
	
	setTimeout(function(){$('.container').show();},1000);
});
//查看心愿单详情
function seeWishInfo(id){
	if(id){
		$.ajax({
			type: "GET",
			url: "ra_ajax.php?see_wish_info=1&id="+id,
			dataType:'json',
			success: function(data){
				if(data.result == 'success'){
					$('#seeWishInfoDiv').html(data.str);
					getWidth(); 
					$('#wishlist').fadeOut(500);
					$('#seeWishInfoDiv').fadeIn(500);
					
					$('#unrealized_2,#Realized_2,#evaluate_2').click(function(){
						$('#seeWishInfoDiv').html('');
						$('#seeWishInfoDiv').fadeOut(500);
						$('#wishlist').fadeIn(500);
					});
					
					//点击星星评价
					$('.star').click(function(){
						starcount=$(this).attr('id').substr(5,1);
						for(var i=1;i<=5;i++){
							if(i > starcount){
								$('#star_'+i).attr('src','images/star_1.png');
							}else{
								$('#star_'+i).attr('src','images/star_2.png');
							}
						}
					});
				}
			}
		});
	}
}
//提交评价
function subEvaluate(wid){
	if(checkForm()){
		var content=trim($('#Realized_6').val());
		$.ajax({
			type: "GET",
			url: "ra_ajax.php?sub_evaluate=1&wid="+wid+"&content="+content+"&star="+starcount,
			dataType:'json',
			success: function(data){
				if(data.res == 'success'){
					alert('评价成功');
					//$('#seeWishInfoDiv').fadeOut(500);
					$('#seeWishInfoDiv').html(data.str);
					getWidth();
					//$('#seeWishInfoDiv').fadeIn(500);
					$('#wishlist_4_'+wid).html('【已评价】');
					$('#wishlist_5_div_'+wid).html('');
					
					$('#evaluate_2').click(function(){
						$('#seeWishInfoDiv').html('');
						$('#seeWishInfoDiv').fadeOut(500);
						$('#wishlist').fadeIn(500);
					});
				}
			}
		});
	}
}
function checkForm(){
	if(starcount == 0){
		alert('请选择星级');
		return false;
	}
	if(trim($('#Realized_6').val()) == ''){
		alert('请输入评价');
		return false;
	}
	return true;
}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function getWidth(){
	$('.container').width(x).height(y);
	$('#wishbg,#unrealizedbg,#wishfooterbg,#Realizedbg,#evaluatebg').width(x);
	$('#wishbottom').width(x).height(101/p).css({left:0,bottom:0});
	$('#wishlist').width(638/p).height(1017/p).css({left:(x-638/p)/2+'px',top:153/p+'px'});
	$('#wishlist li').width(638/p).height(238/p).css({marginTop:15/p+'px'});
	$('.wishlibg').width(638/p).height(238/p);
	$('.wishlist_1').width(113/p).height(160/p).css({left:42/p+'px',top:40/p+'px'});
	$('.wishlist_2').width(110/p).height(58/p).css({left:195/p+'px',top:113/p+'px'});
	$('.wishlist_5').width(110/p).height(58/p).css({left:327/p+'px',top:113/p+'px'});
	$('.wishlist_3').css({left:195/p,top:41/p+'px',fontSize:30/p+'px'});
	$('.wishlist_4').css({left:444/p,top:41/p+'px',fontSize:30/p+'px'});
	
	$('#wishfooter').width(x).height(251/p).css({left:0,bottom:0});
	$('#wishfooterbt').width(596/p).height(111/p).css({left:(x-596/p)/2+'px',top:112/p+'px'});
	
	//未实现
	$('#unrealized').width(x).height(y).css({left:0,top:0});
	$('#unrealizedbar').width(556/p).height(605/p).css({left:(x-556/p)/2+'px',top:527/p+'px'});
	$('#unrealized_1').width(166/p).height(235/p).css({left:(x-166/p)/2+'px',top:241/p+'px'});
	$('#unrealized_2').width(206/p).height(58/p).css({marginLeft:175/p+'px',marginTop:160/p+'px'});
	$('#unrealized_3').css({width:500/p+'px',marginLeft:16/p+'px',fontSize:26/p+'px'});
	$('#unrealized_4').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	$('#unrealized_5').width(556/p).height(1/p).css({marginTop:20/p+'px'});
	$('#unrealized_6').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	
	//已实现
	$('#Realized').width(x).height(y).css({left:0,top:0});
	$('#Realizedbar').width(556/p).height(605/p).css({left:(x-556/p)/2+'px',top:527/p+'px'});
	$('#starbar').width(464/p).height(59/p).css({marginLeft:37/p+'px',marginTop:30/p+'px'});
	$('#Realized_1').width(166/p).height(235/p).css({left:(x-166/p)/2+'px',top:241/p+'px'});
	$('#Realized_2').width(256/p).height(57/p).css({marginLeft:16/p+'px',marginTop:20/p+'px'});
	$('#Realized_3').width(256/p).height(57/p).css({marginLeft:16/p+'px',marginTop:20/p+'px'});
	$('#Realized_4').css({width:540/p+'px',marginLeft:16/p+'px',fontSize:26/p+'px'});
	$('#Realized_5').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	$('#Realized_6').css({width:526/p+'px',height:152/p+'px',marginLeft:16/p+'px',marginTop:30/p+'px',fontSize:26/p+'px'});
	$('#Realized_7').width(556/p).height(1/p).css({marginTop:20/p+'px'});
	$('#Realized_8').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	$('.star,.stars').width(62/p).height(59/p);
	$('#star_1').css({left:0,top:0});
	$('#star_2').css({left:99/p+'px',top:0});
	$('#star_3').css({left:200/p+'px',top:0});
	$('#star_4').css({left:298/p+'px',top:0});
	$('#star_5').css({left:397/p+'px',top:0});
	
	//已评价
	$('#evaluate').width(x).height(y).css({left:0,top:0});
	$('#evaluatebar').width(556/p).height(605/p).css({left:(x-556/p)/2+'px',top:527/p+'px'});
	$('#starsbar').width(464/p).height(59/p).css({marginLeft:37/p+'px',marginTop:30/p+'px'});
	$('#evaluate_1').width(166/p).height(235/p).css({left:(x-166/p)/2+'px',top:241/p+'px'});
	$('#evaluate_2').width(191/p).height(57/p).css({marginLeft:175/p+'px',marginTop:20/p+'px'});
	$('#evaluate_3').css({width:540/p+'px',marginLeft:16/p+'px',fontSize:26/p+'px'});
	$('#evaluate_4').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	$('#evaluate_5').css({width:526/p+'px',height:152/p+'px',marginLeft:16/p+'px',marginTop:30/p+'px',fontSize:26/p+'px'});
	$('#evaluate_6').width(556/p).height(1/p).css({marginTop:20/p+'px'});
	$('#evaluate_7').css({width:540/p+'px',marginLeft:16/p+'px',marginTop:20/p+'px',fontSize:26/p+'px'});
	$('#stars_1').css({left:0,top:0});
	$('#stars_2').css({left:99/p+'px',top:0});
	$('#stars_3').css({left:200/p+'px',top:0});
	$('#stars_4').css({left:298/p+'px',top:0});
	$('#stars_5').css({left:397/p+'px',top:0});
}
</script>
<?php $db->ig2_update('mae_wish_list',array('is_see'=>1),'uid='.$user['id'].' and status=2 and is_see=0');?> 	
</body>
<?php }?>
</html>
